var t = getApp();

Page({
    data: {
        active: 0,
        type: "",
        rewardsData: {},
        recordsList: [],
        activeName: "-1",
        WXtitle: "",
        api: "",
        listApi: "",
        isLoadMore: !0,
        page: 1,
        total_page: 0
    },
    onLoad: function(t) {
        this.setData({
            type: t.name,
            WXtitle: t.reward_name
        }), this.data.WXtitle && wx.setNavigationBarTitle({
            title: this.data.WXtitle
        }), 1 == this.options.fromHome && (this.initData(this.data.type), this.getIndex(), 
        this.getData());
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {},
    toDetail: function(t) {
        var a = t.currentTarget.dataset.item || t.target.dataset.item;
        wx.navigateTo({
            url: "/packageB/member/enterprise/AwardDetail/AwardDetail?name=" + this.data.type + "&id=" + a.id
        });
    },
    getTab: function(t) {
        0 == t.detail.index ? this.setData({
            activeName: "-1"
        }) : 1 == t.detail.index ? this.setData({
            activeName: "1"
        }) : 2 == t.detail.index && this.setData({
            activeName: "0"
        }), this.getData();
    },
    initData: function(t) {
        switch (t) {
          case "teamManagement":
            this.setData({
                api: "plugin.mryt.api.team-manage.index",
                listApi: "plugin.mryt.api.team-manage.getList"
            });
            break;

          case "team":
            this.setData({
                api: "plugin.mryt.api.team.index",
                listApi: "plugin.mryt.api.team.getList"
            });
            break;

          case "thanks":
            this.setData({
                api: "plugin.mryt.api.thanksgiver.index",
                listApi: "plugin.mryt.api.thanksgiver.getList"
            });
            break;

          case "education":
            this.setData({
                api: "plugin.mryt.api.train.index",
                listApi: "plugin.mryt.api.train.getList"
            });
            break;

          case "immediate":
            this.setData({
                api: "plugin.mryt.api.direct-award.index",
                listApi: "plugin.mryt.api.direct-award.getList"
            });
            break;

          case "tier":
            this.setData({
                api: "plugin.mryt.api.tier.index",
                listApi: "plugin.mryt.api.tier.getList"
            });
            break;

          default:
            this.setData({
                WXtitle: "奖励记录"
            });
        }
    },
    getIndex: function() {
        var a = this, i = t.getNetAddresss(this.data.api);
        t._getNetWork({
            url: i,
            success: function(t) {
                var i = t.data;
                1 === i.result ? a.setData({
                    rewardsData: i.data
                }) : wx.showToast({
                    title: i.msg,
                    icon: "none"
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    getData: function() {
        var a = this, i = t.getNetAddresss(this.data.listApi);
        i += "&status=" + this.data.activeName, t._getNetWork({
            url: i,
            success: function(t) {
                var i = t.data;
                1 === i.result ? a.setData({
                    recordsList: i.data.data,
                    total_page: i.data.last_page,
                    isLoadMore: !0
                }) : wx.showToast({
                    title: i.msg,
                    icon: "none"
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    }
});